﻿package com.mui.controls
{
    import com.mui.utils.*;
    import flash.display.*;
    import flash.text.*;

    public class GTextFiledBitmap extends Bitmap implements IDispose
    {
        private var _txtWidth:Number;
        private var _txtHeight:Number;
        private var _filters:Array;
        private var _textFormat:TextFormat;
        private var _text:String;
        private var _htmlText:String;
        private var _bitmapDataClone:BitmapData;
        public static var textFiled:GTextFiled = new GTextFiled();

        public function GTextFiledBitmap(param1:BitmapData = null, param2:String = "auto", param3:Boolean = false)
        {
            super(param1, param2, param3);
            return;
        }// end function

        public function set txtWidth(param1:Number) : void
        {
            this._txtWidth = param1;
            return;
        }// end function

        public function get txtWidth() : Number
        {
            return this._txtWidth;
        }// end function

        public function set txtHeight(param1:Number) : void
        {
            this._txtHeight = param1;
            return;
        }// end function

        public function get txtHeight() : Number
        {
            return this._txtHeight;
        }// end function

        public function set txtFilters(param1:Array) : void
        {
            this._filters = param1;
            return;
        }// end function

        public function set textFormat(param1:TextFormat) : void
        {
            this._textFormat = param1;
            return;
        }// end function

        public function set text(param1:String) : void
        {
            this._text = param1;
            this.draw(param1, false);
            return;
        }// end function

        public function get text() : String
        {
            return this._text;
        }// end function

        public function set htmlText(param1:String) : void
        {
            this._htmlText = param1;
            this.draw(param1, true);
            return;
        }// end function

        public function get htmlText() : String
        {
            return this._htmlText;
        }// end function

        private function draw(param1:String, param2:Boolean) : void
        {
            if (textFiled.defaultTextFormat != this._textFormat)
            {
                textFiled.defaultTextFormat = this._textFormat;
            }
            if (param2)
            {
                textFiled.htmlText = param1;
            }
            else
            {
                textFiled.text = param1;
            }
            textFiled.width = this._txtWidth;
            textFiled.height = this._txtHeight;
            textFiled.filters = this._filters;
            this.bitmapData = this._bitmapDataClone;
            this.bitmapData.draw(textFiled);
            return;
        }// end function

        override public function set bitmapData(param1:BitmapData) : void
        {
            this._bitmapDataClone = param1.clone();
            super.bitmapData = param1;
            return;
        }// end function

        public function dispose(param1:Boolean = true) : void
        {
            this._text = "";
            this._htmlText = "";
            this._txtWidth = 0;
            this._txtHeight = 0;
            this._textFormat = null;
            this._filters = null;
            this._bitmapDataClone.dispose();
            this.bitmapData.dispose();
            this._bitmapDataClone = null;
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            if (param1)
            {
                UICompomentPool.disposeUICompoment(this);
            }
            return;
        }// end function

        textFiled.multiline = true;
        textFiled.wordWrap = true;
    }
}
